$$3.ready(function() {
    connect();
});

function connect() {
    var id = $$3.url.getParameter("id");
    document.getElementById("userno").innerHTML = id;
    
    // 向服务器发起websocket连接并发送CONNECT帧
    //$$3.socket.endpoint = "http://39.104.96.32:8027/WebSocketEndpoint";
    //$$3.socket.endpoint = "ws://localhost:9999/websocket/"+id;
    $$3.socket.endpoint = "/websocket/"+id;
    $$3.socket.connect(
           function(frame) {
               // 连接成功时（服务器响应 CONNECTED 帧）的回调方法
               showLog("链接成功！");
               //连接成功后订阅/topic/getResponse目标发送的消息，该地址在Controller中用@SendTo指定
               $$3.socket.subscribe('/WebSocketTopic/d02', function(response) {
                   showResponse(JSON.parse(response.body).message);
               });
           }
           , function(frame) {
               // 连接失败时（服务器响应 ERROR 帧）的回调方法
               showLog("链接失败！");
               //console.log(frame);
               //console.log("=================================");
               $$3.socket.disconnect();
               setTimeout(connect, 3000);
           });        
}


function showResponse(message) {
    $("#showResult").prepend("<br/>").prepend(message);
}
function showLog(message) {
    console.log(message);
    $("#message").prepend("<br/>").prepend(message);
}